package services

import (
	"bytes"
	"encoding/json"
	"fmt"
	"io"
	"net/http"
)

func push_weixin_markdown(key string, pushType GitPushType, content string) int {
	md_map := map[string]any{
		"msgtype": "markdown",
		"markdown": map[string]any{
			"content": content,
		},
	}
	data, _ := json.Marshal(md_map)
	reader := bytes.NewReader(data)
	url := fmt.Sprintf("https://qyapi.weixin.qq.com/cgi-bin/webhook/send?key=%s", key)
	resp, err := http.Post(url, "application/json", reader)
	if err != nil {
		return 0
	}
	defer resp.Body.Close()
	data, err = io.ReadAll(resp.Body)
	if err != nil {
		return 0
	}
	fmt.Println("push_weixin_markdown done ", string(data))
	return 1
}
